package be.kuleuven.cs.mop.domain.model.impl;


import static org.junit.Assert.*;

import org.junit.*;

import be.kuleuven.cs.mop.TestEnvironment;
import be.kuleuven.cs.mop.domain.exceptions.TaskManagerException;



public class ProjectImplTest{
	
	private static TestEnvironment ENV;
	
	private static ProjectImpl	constructorTest1;
	private static String		testDescription1, testDescription2;
	private static ProjectImpl	testProject, testProject2;
	
	
	
	@Before
	public void setUp() throws Exception {
		ENV = TestEnvironment.newInstance();
		
		testDescription1	= "Test Description1";
		testDescription2	= "Test Description2";
		
		testProject		= new ProjectImpl(ENV.world, testDescription1);
		testProject2	= new ProjectImpl(ENV.world, testDescription2);
	}
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {}
	
	@After
	public void tearDown() throws Exception {}
	
	@AfterClass
	public static void tearDownAfterClass() throws Exception {}
	
	@Test
	public void testConstructorBaseCase() throws TaskManagerException {
		constructorTest1 = new ProjectImpl(ENV.world, "this is a test");
		assertEquals(constructorTest1.getWorld(),		ENV.world);
		assertEquals(constructorTest1.getDescription(),	"this is a test");
	}
	
	@Test(expected=NullPointerException.class)
	public void testConstructorIllegalCase0() throws TaskManagerException {
		new ProjectImpl(null, "valid");
	}
	
	@Test(expected=TaskManagerException.class)
	public void testConstructorIllegalCase1() throws TaskManagerException{
		new ProjectImpl(ENV.world, "");
	}
	
	@Test(expected=TaskManagerException.class)
	public void testConstructorIllegalCase2() throws TaskManagerException{
		new ProjectImpl(ENV.world, null);
	}
	
	@Test
	public void testAssignTaskBaseCase() throws TaskManagerException{
		testProject.assignTask(ENV.task1);
		assertTrue(testProject.getTasks().contains(ENV.task1));
		assertTrue(ENV.task1.getProject().equals(testProject));
	}
	
	@Test (expected=TaskManagerException.class)
	public void testAssignTaskInvalidNull() throws TaskManagerException{
		testProject.assignTask(null);
	}
	
	@Test
	public void testAssignTaskValid() throws TaskManagerException{
		assertFalse(testProject.getTasks().contains(ENV.task1));
		assertTrue(testProject.getTasks().isEmpty());
		assertFalse(testProject2.getTasks().contains(ENV.task1));
		assertTrue(testProject2.getTasks().isEmpty());
		
		testProject.assignTask(ENV.task1);
		assertTrue(ENV.task1.getProject().equals(testProject));
		assertFalse(testProject.getTasks().isEmpty());
		
		assertTrue(testProject.getTasks().contains(ENV.task1));
		assertFalse(testProject2.getTasks().contains(ENV.task1));
		
		testProject2.assignTask(ENV.task1);
		assertTrue(ENV.task1.getProject().equals(testProject2));
		assertFalse(testProject2.getTasks().isEmpty());
		
		assertFalse(testProject.getTasks().contains(ENV.task1));
		assertTrue(testProject2.getTasks().contains(ENV.task1));
	}
	
	@Test
	public void testRemove() throws TaskManagerException {
		final ProjectImpl project = new ProjectImpl(ENV.world, "valid");
		assertTrue(ENV.world.getProjects().contains(project));
		project.remove();
		assertFalse(ENV.world.getProjects().contains(project));
	}
	
	@Test
	public void testValidation() {
		assertFalse(testProject.toString().isEmpty());
//		assertFalse(ProjectImpl.isValidDescription(null));
//		assertFalse(ProjectImpl.isValidDescription(""));
//		assertFalse(ProjectImpl.isValidTask(null));
	}
	
}